//
//  XHGuidePageViewController.m
//  elxc
//
//  Created by 冷山 on 16/4/6.
//  Copyright © 2016年 lexingsoft. All rights reserved.
//

#import "XHGuidePageViewController.h"
#import "XHTabBarController.h"
#import "AppDelegate.h"

#define SCREEN_WIDTH            ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT           ([UIScreen mainScreen].bounds.size.height)

#define BUTTON_WIDTH  (480 == [UIScreen mainScreen].bounds.size.height ? 125 : 568 == [UIScreen mainScreen].bounds.size.height ? 125 :667 == [UIScreen mainScreen].bounds.size.height ? 150:736 == [UIScreen mainScreen].bounds.size.height ? 150 :NO)

#define BUTTON_HEIGHT (480 == [UIScreen mainScreen].bounds.size.height ? 40 : 568 == [UIScreen mainScreen].bounds.size.height ? 40 :667 == [UIScreen mainScreen].bounds.size.height ? 45:736 == [UIScreen mainScreen].bounds.size.height ? 45 :NO)

#define BOTTOM_HEIGHT (480 == [UIScreen mainScreen].bounds.size.height ? 97 : 568 == [UIScreen mainScreen].bounds.size.height ? 118 :667 == [UIScreen mainScreen].bounds.size.height ? 140:736 == [UIScreen mainScreen].bounds.size.height ? 160 :NO)

@interface XHGuidePageViewController ()<UIScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UIScrollView *ui_scrollView;
@property (strong, nonatomic) UIImageView * ui_imageView;
@property (strong, nonatomic) NSArray * m_imageArr;
@property (strong, nonatomic) UIButton * btn;

@end

@implementation XHGuidePageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    if (SCREEN_HEIGHT == 480)
    {
        self.m_imageArr = @[@"gudie960-1",@"gudie960-2",@"gudie960-3",@"gudie960-4"];
    }
    else if (SCREEN_HEIGHT == 568)
    {
        self.m_imageArr = @[@"gudie1334-1",@"gudie1334-2",@"gudie1334-3",@"gudie1334-4"];
    }
    else if (SCREEN_HEIGHT == 667)
    {
        self.m_imageArr = @[@"gudie1334-1",@"gudie1334-2",@"gudie1334-3",@"gudie1334-4"];
    }
    else if (SCREEN_HEIGHT == 736)
    {
        self.m_imageArr = @[@"gudie1334-1",@"gudie1334-2",@"gudie1334-3",@"gudie1334-4"];
    }
    
    [self scrollView];

}

- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    for (int i = 0; i < self.m_imageArr.count; i++)
    {
        UIImage * image = [UIImage imageNamed:self.m_imageArr[i]];
        self.ui_imageView = [[UIImageView alloc]initWithImage:image];
        [self.ui_scrollView addSubview:self.ui_imageView];
        
        CGRect frame=CGRectZero;
        frame.origin.x = i * self.ui_scrollView.frame.size.width;
        frame.origin.y = 0;
        frame.size = self.ui_scrollView.frame.size;
        self.ui_imageView.frame=frame;
    }
    self.ui_scrollView.contentSize = CGSizeMake(self.ui_scrollView.frame.size.width * self.m_imageArr.count,
                                                self.ui_scrollView.frame.size.height);
    self.btn.frame = CGRectMake(SCREEN_WIDTH*3.5-BUTTON_WIDTH/2,SCREEN_HEIGHT-BOTTOM_HEIGHT,BUTTON_WIDTH,BUTTON_HEIGHT);
    [self.ui_scrollView addSubview:self.btn];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)scrollView
{
    self.ui_scrollView.delegate = self;
    self.btn = [UIButton buttonWithType:UIButtonTypeCustom];
    if (SCREEN_HEIGHT == 480)
    {
        [self.btn setImage:[UIImage imageNamed:@"noraml960"] forState:UIControlStateNormal];
        [self.btn setImage:[UIImage imageNamed:@"select960"] forState:UIControlStateHighlighted];
    }
    else if (SCREEN_HEIGHT == 568)
    {
        [self.btn setImage:[UIImage imageNamed:@"noraml1334"] forState:UIControlStateNormal];
        [self.btn setImage:[UIImage imageNamed:@"select1334"] forState:UIControlStateHighlighted];
    }
    else if (SCREEN_HEIGHT == 667)
    {
        [self.btn setImage:[UIImage imageNamed:@"noraml1334"] forState:UIControlStateNormal];
        [self.btn setImage:[UIImage imageNamed:@"select1334"] forState:UIControlStateHighlighted];
    }
    else if (SCREEN_HEIGHT == 736)
    {
        [self.btn setImage:[UIImage imageNamed:@"noraml1334"] forState:UIControlStateNormal];
        [self.btn setImage:[UIImage imageNamed:@"select1334"] forState:UIControlStateHighlighted];
    }
    [self.btn addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside];
    
}

- (void)onClick:(UIButton*)btn
{
    AppDelegate *delegate=[UIApplication sharedApplication].delegate;
    [delegate finishLaunching];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
